#!/usr/bin/env node

const program = require('commander');
const process1 = require('child_process');
const readline = require('readline')
//version 版本号
//name 新项目名称

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

function gitClone(name, url) {
    process1.exec('git clone ' + url + ' ' + name, function (error, stdout, stderr) {
        if (error !== null) {
            console.log('exec error: ' + error);
            return;
        }
        console.log(stdout);
        console.log('clone success');
    });
}

program.version('1.0.3', '-v, --version')
    .command('init <name>')
    .action((name) => {
        console.log('clone template ...');
        rl.question('你是使用react h5模板吗?(y/n)', function (input) {
            console.log('你输入了:', input);
            if (input !== 'y' && input !== 'Y') {
                rl.question('你将要使用微前端基座', function (input) {
                    // console.log('你输入了:', input);
                    gitClone(name, 'https://gitee.com/chenxingwull/zb-cli.git')
                })
            } else {
                gitClone(name, 'https://gitee.com/chenxingwull/h5-modal.git')
            }
        })
    });
program.parse(process.argv);
